#ifndef __INC_EXT_SBMEM_H__
#define __INC_EXT_SBMEM_H__

#if _MSC_VER
#pragma once
#endif

#define KMEM_GAP						4
#define KMEM_PARA_SIZE					16
#define KMEM_PARA_PAGE					256
#define KMEM_PAGE_SIZE					(KMEM_PARA_SIZE*KMEM_PARA_PAGE)
#define KMEM_DBG						K_MAKEFOURCC('D','B','G',0)
#define KMEM_END						K_MAKEFOURCC('E','N','D',0)

// memory block
typedef struct kMemBlock
{
	struct kMemBlock*	next;
	struct kMemBlock*	prev;

	const char*			filename;
	kushort				line;

	kushort				type;
	kuint				req;
	ksize_t				index;

	ksize_t				size;
	ksize_t				block;

#if !_SB_64_
	ksize_t				align[3];
#endif

	ksize_t				gap;
	/*
	and internal addition
		kbyte			data[data size]
		kbyte			endgap[KMEM_GAP]
	*/
} kMemBlock;
	
#define k_memhdr(p)						(((kMemBlock*)(p))-1)
#define k_memptr(p)						(((kMemBlock*)(p))+1)
#define k_membsize(size)				(((sizeof(kMemBlock)+(size)+KMEM_GAP)+KMEM_PARA_SIZE-1)&~(KMEM_PARA_SIZE-1))

#endif	// __INC_EXT_SBMEM_H__
